<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || ${lesson.name}</title>
        ${stylesheet}
        ${jquery}
        ${jsdropdown}
        ${chat}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>${lesson.name}</h1>
                <c:if test="${isFree}">
                    <center>
                        <c:choose>
                            <c:when test="${isGuest}">
                                <h4><b><a href="Register">This is a free lesson. Purchase the entire ${lesson.course.name} course now! Sign up!</a></b></h4>
                            </c:when>
                            <c:otherwise>
                                <h4><b><a href="CartController?courseid=${lesson.course.id}&redirect=true">This is a free lesson. Purchase the entire ${lesson.course.name} course now!</a></b></h4>
                            </c:otherwise>
                        </c:choose>
                    </center>
                </c:if>
                <c:choose><c:when test="${!lesson.liveLesson}">
                        <form action="LectureController" method="GET">
                            <div class="relative">
                                <select class="select" name="viewfileid" id="presentationlist">
                                    <option value="-">Select a file to view</option>
                                    <c:forEach items="${viewfiles}" var="viewfiles">
                                        <option value="${viewfiles.id}" name="viewfileid">${viewfiles.name}</option>
                                    </c:forEach>
                                </select>
                                <c:if test="${isFree}"><input type="hidden" name="isFree" value="true"/></c:if>
                                    <span class="pointer"></span>
                                </div>
                                <input type="hidden" value="${lesson.id}" name="id"/>
                            <input type="submit" value="View"/>
                        </form>
                        <div class="clear margin-bottom-10"></div>
                        <div class="full-block">

                            <c:choose>
                                <c:when test="${mainfile!=null}">
                                    <img src="${url}images/current-view.png"/> View ${mainfile.type} ${mainfile.name}</br><center><iframe src="http://docs.google.com/gview?url=${url}${mainfile.url}&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe></center>
                                    </c:when>
                                    <c:otherwise>There is no file to view.</c:otherwise>
                            </c:choose>
                        </div>
                    </c:when>
                    <c:otherwise>
                        <!--- LIVE LESSON !--->
                        <div class="full-block">
                            <h4 class="search">Live lesson</h4>
                            <center>
                                <c:choose><c:when test="${liveLesson.status eq 'not started'}">
                                        <!--- LIVE LESSON NOT STARTED YET !--->
                                        <c:if test="${isTeacher}">
                                            <form action="LiveLessonStatus" method="POST">
                                                <input type="hidden" value="${lesson.id}" name="lessonid"/>
                                                <input type="hidden" value="started" name="status"/>
                                                <input type="submit" value="Start live lesson" name="start"/>
                                            </form>
                                        </c:if>
                                        <h3>This live lesson starts on:</h3>
                                        <h1> ${timeAndDate} </h1>
                                    </center>
                                </div>
                            </c:when>
                            <c:when test="${liveLesson.status eq 'stopped'}">
                                <!--- LIVE LESSON STOPPED !--->
                                <h3>This live lesson session has been stopped.</h3>
                                <c:if test="${isTeacher}">
                                    <form action="LiveLessonStatus" method="POST">
                                        <input type="hidden" value="${lesson.id}" name="lessonid"/>
                                        <input type="hidden" value="started" name="status"/>
                                        <input type="submit" value="Start live lesson" name="start"/>
                                    </form>
                                </c:if>
                                </center>
                            </div>
                        </c:when>
                        <c:otherwise>
                            <object type="application/x-shockwave-flash" data="http://www.justin.tv/widgets/live_embed_player.swf?channel=${embedStream}" id="live_embed_player_flash" height="500" width="756" bgcolor="#000000"><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="all" /><param name="movie" value="http://www.justin.tv/widgets/live_embed_player.swf" /><param name="flashvars" value="hostname=www.justin.tv&channel=${embedStream}&auto_play=true&start_volume=25" /></object>
                            <br />
                            <!--- LIVE LESSON STARTED !--->
                            <c:if test="${isTeacher}">You are a teacher for this course.

                                <form action="LiveLessonStatus" method="POST">
                                    <input type="hidden" value="${lesson.id}" name="lessonid"/>
                                    <input type="hidden" value="stopped" name="status"/>
                                    <input type="submit" value="Stop live lesson" name="stop"/>
                                </form>
                            </c:if>
                            </br>
                            <div style="float: left; width: 49%;">Chat</div>
                            <c:if test="${isTeacher}">
                                <div style="float: left; width: 49%;">Questions from students</div>
                            </c:if>
                            <div class="clear"></div>
                            <div id="chatwindow">
                                Welcome to this live lecture!</br>
                            </div>
                            <c:if test="${isTeacher}">
                                <div id="questionwindow">
                                    Questions from students:</br>
                                </div>
                            </c:if>
                            <div class="clear"></div>
                            <c:if test="${sessionScope.user!=null}"> <!--- If the user is logged in !--->
                                <form action="" name="chatform" id="chatform">
                                    <input type="hidden" id="lessonid" name="lessonid" value="${lesson.id}"/>
                                    <input type="text" id="message" name="message" style="width:270px; margin-right: 5px;" maxlength="90"/> 
                                    <input type="radio" id="chat" name="chattype" value="chat" checked> <label for="chat" class="radio"> <img src="${url}images/chat.png" style="vertical-align: sub;" /></label>
                                    <input type="radio" id="question" name="chattype" value="question" style="margin-left: 3px;"> <label for="question" class="radio"> <img src="${url}images/question_1.png" style="vertical-align: sub;" /></label>
                                    <input type="submit" name="submit" class="button" id="button" style="margin-left: 2px;" value="Send" />  
                                </form>
                            </c:if>

                        </center>
                    </div>
                </c:otherwise></c:choose>
        </c:otherwise>
    </c:choose>
    <div class="clear margin-bottom-10"></div>
    <div class="full-block">
        <c:choose>
            <c:when test="${isFree}">
                <img src="${url}images/free-lesson.jpg"/>
            </c:when>
            <c:otherwise>
                <A NAME="NOTE"></A>
                <h4 class="search"><img src="${url}images/noteiconbg.jpg"/> Notes made in ${lesson.name}</h4>
                </br>
                <form action="ManageNote" method="POST">
                    <center><textarea id="styled" name="text"><c:choose><c:when test="${note!=null}">${note.text}</c:when></c:choose></textarea>
                                </br>
                                <input type="hidden" value="${lesson.id}" name="lessonid"/>
                        <input type="submit" value="Save note"/>
                </form>
            </center>
        </c:otherwise>
    </c:choose>
</div>

<div class="clear margin-bottom-10"></div>
<div class="full-block">
    <h4 class="search"><img src="${url}images/assignmenticon.jpg"/> Assignments of ${lesson.name}</h4>
    <table class="overview">
        <tr>
            <th style="width: 160px;">Filename</th>
            <th>Original filename</th>
            <th class="date">Date added</th>
            <c:if test="${sessionScope.userrole eq 'Student'}"> 

                <th style="width: 76px;">Handed in</th>
                <th style="width: 60px;">Grade</th>
                <th style="width: 60px;">Hand-in</th>

            </c:if>
        </tr>
        <c:forEach items="${assignment}" var="assignment">
            <c:set var="i" value="${i + 1}"/>
            <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                <td><a href="${url}${assignment.url}" class="hidden"></a>${assignment.name}</td>
                <td>${assignment.fileName}</td>
                <td>${assignment.date}</td>
                <c:if test="${sessionScope.userrole eq 'Student'}">
                    <td>

                        <c:set var="handed_in" value="false"/>    
                        <c:forEach items="${handedassignments}" var="handedassignments">
                            <c:if test="${handedassignments.assignment.id==assignment.id}">
                                <c:set var="handed_in" value="true"/>
                            </c:if>
                        </c:forEach>
                <center>
                    <c:if test="${handed_in==true}">Yes</c:if>
                    <c:if test="${handed_in==false}">No</c:if>
                    </center>
                    </td>
                    <td>
                    <c:set var="handed_inp" value="false"/>    
                    <c:set var="gradex" value="0"/>
                    <c:forEach items="${handedassignments}" var="handedassignments">
                        <c:choose>
                            <c:when test="${handedassignments.assignment.id==assignment.id}">
                                <c:set var="handed_inp" value="true"/>
                                <c:set var="gradex" value="${handedassignments.grade}"/>
                            </c:when><c:otherwise></c:otherwise>
                        </c:choose>
                    </c:forEach>
                    <c:choose><c:when test="${gradex eq '0'}"><center>-</center></c:when><c:otherwise><center>${gradex}</center></c:otherwise></c:choose>
                        </td>
                        <td>
                        <center>
                    <c:choose>
                        <c:when test="${isFree}">
                            FREE TRIAL
                        </c:when>
                        <c:otherwise>
                            <c:choose>
                                <c:when test="${gradex ne '0'}">
                                    <img class="disabled" src="${url}images/handin.png"/>
                                </c:when>
                                <c:otherwise>
                                    <a href="Handin?id=${assignment.id}&lessonid=${lesson.id}"><img src="${url}images/handin.png"/></a>
                                    </c:otherwise>
                                </c:choose>
                            </c:otherwise>
                        </c:choose>
                </center>
                </td></c:if>
                </tr>
        </c:forEach>
    </table>
</center>
</tr>
</table>
<c:choose>
    <c:when test="${fn:length(assignment)==0}">
        There are no assignments at this moment.
    </c:when>
</c:choose>
</div>
</div>
<%@include file="template/footer.jsp" %>
</div>
</body>
</html>
